﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Diagnostics;
using System.ServiceModel;

using WcfCore;

namespace WcfServices
{
	[ServiceContract(Namespace = "http://Wcf/Services")]
	[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
	public class WcfOneWayLatencyTestService : IWcfOneWayLatencyTestServiceContract
	{
		private static readonly Stopwatch _wowltssw = new Stopwatch();
		public static Stopwatch WOWLTSSW
		{
			get
			{
				return _wowltssw;
			}
		}

		private static readonly EventWaitHandle _receiptEvent = new EventWaitHandle(false, EventResetMode.AutoReset, "WcfReceiptEvent");
		public static EventWaitHandle ReceiptEvent
		{
			get
			{
				return _receiptEvent;
			}
		}

		public static double OneWayLatencyMicroSecs
		{
			get
			{
				return ((((double)WOWLTSSW.ElapsedTicks) / WcfTestOutput.TicksPerMicroSec) / 2);
			}
		}

		[OperationContract(IsOneWay = true)]
		public void OneWayLatencyTest()
		{
			WcfOneWayLatencyTestService.WOWLTSSW.Stop();
			ReceiptEvent.Set();
		}
	}
}
